﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Honestysoft.Financing.Model;
using Honestysoft.BaseObject;

namespace Honestysoft.Financing.WebUI.Module.OtherBu.Json
{
    /// <summary>
    /// SaveBankRate 的摘要说明
    /// </summary>
    public class SaveBankRate : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string dataString = context.Request.Params["Data"];
            if (string.IsNullOrEmpty(dataString))
            {
                context.Response.Write(context.Server.UrlEncode("没有需要保存的数据！"));
            }
            else
            {
                string[] arrItem = dataString.Split(',');
                List<Bu_BankRate> lsBankRate = new List<Bu_BankRate>();
                Bu_BankRate item = null;
                string[] arrInv = null;
                foreach (string s in arrItem)
                {
                    arrInv = s.Split('|');
                    item = new Bu_BankRate();
                    item.ID = Honestysoft.BaseLibrary.Common.Guid.GetGuid();
                    item.ActiveDate = Convert.ToDateTime(arrInv[0]);
                    item.Rate = Convert.ToDecimal(arrInv[1]);
                    lsBankRate.Add(item);
                }
                bool bRet = new Honestysoft.Financing.BusinessLogic.Reports("").SaveBankRate(lsBankRate);
                if (bRet)
                {
                    context.Response.Write("0");
                }
                else
                {
                    context.Response.Write(context.Server.UrlEncode("保存失败！"));
                }
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}